﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Pavilion.GameTools;
using System.Xml.Linq;

namespace Pavilion.Locks
{
    public class GroundLock : ILock
    {
        public GroundState GroundState { get; set; }
        public string GameItemName { get; set; }

        public ILock Clone()
        {
            return new GroundLock()
            {
                GameItemName = this.GameItemName,
                GroundState = this.GroundState
            };
        }

        public void Deserialize(XElement lockElement, string resourceName)
        {
            GroundState = (GroundState)Enum.Parse(typeof(GroundState), lockElement.Attribute("GroundState").Value);
        }

        public XElement Serialize()
        {
            XElement lockElement = new XElement("Lock");

            lockElement.Add(new XAttribute("GroundState", GroundState));

            return lockElement;
        }

        public LockMonitorBase CreateLockMonitor(GameItem gameItem)
        {
            PhysicalTypeTool physicalType = gameItem.ObtainTool<PhysicalTypeTool>();

            return new LockPredicateMonitor(physicalType, () => physicalType.GroundState == GroundState, this);
        }

        public override string ToString()
        {
            return this.GetType().Name;
        }
    }
}
